function N() {
}
const Ye = (e) => e;
function Be(e) {
  return e();
}
function Te() {
  return /* @__PURE__ */ Object.create(null);
}
function I(e) {
  e.forEach(Be);
}
function X(e) {
  return typeof e == "function";
}
function ye(e, t) {
  return e != e ? t == t : e !== t || e && typeof e == "object" || typeof e == "function";
}
function gt(e) {
  return Object.keys(e).length === 0;
}
function bt(e, ...t) {
  if (e == null)
    return N;
  const n = e.subscribe(...t);
  return n.unsubscribe ? () => n.unsubscribe() : n;
}
function re(e, t, n) {
  e.$$.on_destroy.push(bt(t, n));
}
function C(e, t, n) {
  return e.set(n), t;
}
function vt(e) {
  return e && X(e.destroy) ? e.destroy : N;
}
const We = typeof window < "u";
let Ke = We ? () => window.performance.now() : () => Date.now(), Ee = We ? (e) => requestAnimationFrame(e) : N;
const J = /* @__PURE__ */ new Set();
function Ve(e) {
  J.forEach((t) => {
    t.c(e) || (J.delete(t), t.f());
  }), J.size !== 0 && Ee(Ve);
}
function Ge(e) {
  let t;
  return J.size === 0 && Ee(Ve), {
    promise: new Promise((n) => {
      J.add(t = { c: e, f: n });
    }),
    abort() {
      J.delete(t);
    }
  };
}
function we(e, t) {
  e.appendChild(t);
}
function yt(e, t, n) {
  const o = pe(e);
  if (!o.getElementById(t)) {
    const i = q("style");
    i.id = t, i.textContent = n, Je(o, i);
  }
}
function pe(e) {
  if (!e)
    return document;
  const t = e.getRootNode ? e.getRootNode() : e.ownerDocument;
  return t && t.host ? t : e.ownerDocument;
}
function Et(e) {
  const t = q("style");
  return Je(pe(e), t), t.sheet;
}
function Je(e, t) {
  return we(e.head || e, t), t.sheet;
}
function H(e, t, n) {
  e.insertBefore(t, n || null);
}
function F(e) {
  e.parentNode && e.parentNode.removeChild(e);
}
function wt(e, t) {
  for (let n = 0; n < e.length; n += 1)
    e[n] && e[n].d(t);
}
function q(e) {
  return document.createElement(e);
}
function Se(e) {
  return document.createTextNode(e);
}
function Qe() {
  return Se(" ");
}
function Ue() {
  return Se("");
}
function ie(e, t, n, o) {
  return e.addEventListener(t, n, o), () => e.removeEventListener(t, n, o);
}
function A(e, t, n) {
  n == null ? e.removeAttribute(t) : e.getAttribute(t) !== n && e.setAttribute(t, n);
}
function pt(e) {
  return Array.from(e.childNodes);
}
function St(e, t) {
  t = "" + t, e.wholeText !== t && (e.data = t);
}
function Ae(e, t, n) {
  e.classList[n ? "add" : "remove"](t);
}
function Ot(e, t, { bubbles: n = !1, cancelable: o = !1 } = {}) {
  const i = document.createEvent("CustomEvent");
  return i.initCustomEvent(e, n, o, t), i;
}
const fe = /* @__PURE__ */ new Map();
let ce = 0;
function xt(e) {
  let t = 5381, n = e.length;
  for (; n--; )
    t = (t << 5) - t ^ e.charCodeAt(n);
  return t >>> 0;
}
function kt(e, t) {
  const n = { stylesheet: Et(t), rules: {} };
  return fe.set(e, n), n;
}
function Xe(e, t, n, o, i, l, c, u = 0) {
  const r = 16.666 / o;
  let s = `{
`;
  for (let b = 0; b <= 1; b += r) {
    const v = t + (n - t) * l(b);
    s += b * 100 + `%{${c(v, 1 - v)}}
`;
  }
  const a = s + `100% {${c(n, 1 - n)}}
}`, d = `__svelte_${xt(a)}_${u}`, f = pe(e), { stylesheet: h, rules: g } = fe.get(f) || kt(f, e);
  g[d] || (g[d] = !0, h.insertRule(`@keyframes ${d} ${a}`, h.cssRules.length));
  const w = e.style.animation || "";
  return e.style.animation = `${w ? `${w}, ` : ""}${d} ${o}ms linear ${i}ms 1 both`, ce += 1, d;
}
function _e(e, t) {
  const n = (e.style.animation || "").split(", "), o = n.filter(
    t ? (l) => l.indexOf(t) < 0 : (l) => l.indexOf("__svelte") === -1
  ), i = n.length - o.length;
  i && (e.style.animation = o.join(", "), ce -= i, ce || Lt());
}
function Lt() {
  Ee(() => {
    ce || (fe.forEach((e) => {
      const { ownerNode: t } = e.stylesheet;
      t && F(t);
    }), fe.clear());
  });
}
let oe;
function ee(e) {
  oe = e;
}
function Dt() {
  if (!oe)
    throw new Error("Function called outside component initialization");
  return oe;
}
function Nt(e) {
  Dt().$$.on_mount.push(e);
}
const G = [], ge = [];
let Q = [];
const Pe = [], Ct = /* @__PURE__ */ Promise.resolve();
let be = !1;
function Ft() {
  be || (be = !0, Ct.then(Ze));
}
function U(e) {
  Q.push(e);
}
const me = /* @__PURE__ */ new Set();
let K = 0;
function Ze() {
  if (K !== 0)
    return;
  const e = oe;
  do {
    try {
      for (; K < G.length; ) {
        const t = G[K];
        K++, ee(t), Tt(t.$$);
      }
    } catch (t) {
      throw G.length = 0, K = 0, t;
    }
    for (ee(null), G.length = 0, K = 0; ge.length; )
      ge.pop()();
    for (let t = 0; t < Q.length; t += 1) {
      const n = Q[t];
      me.has(n) || (me.add(n), n());
    }
    Q.length = 0;
  } while (G.length);
  for (; Pe.length; )
    Pe.pop()();
  be = !1, me.clear(), ee(e);
}
function Tt(e) {
  if (e.fragment !== null) {
    e.update(), I(e.before_update);
    const t = e.dirty;
    e.dirty = [-1], e.fragment && e.fragment.p(e.ctx, t), e.after_update.forEach(U);
  }
}
function At(e) {
  const t = [], n = [];
  Q.forEach((o) => e.indexOf(o) === -1 ? t.push(o) : n.push(o)), n.forEach((o) => o()), Q = t;
}
let $;
function $e() {
  return $ || ($ = Promise.resolve(), $.then(() => {
    $ = null;
  })), $;
}
function ue(e, t, n) {
  e.dispatchEvent(Ot(`${t ? "intro" : "outro"}${n}`));
}
const se = /* @__PURE__ */ new Set();
let P;
function Oe() {
  P = {
    r: 0,
    c: [],
    p: P
  };
}
function xe() {
  P.r || I(P.c), P = P.p;
}
function k(e, t) {
  e && e.i && (se.delete(e), e.i(t));
}
function M(e, t, n, o) {
  if (e && e.o) {
    if (se.has(e))
      return;
    se.add(e), P.c.push(() => {
      se.delete(e), o && (n && e.d(1), o());
    }), e.o(t);
  } else
    o && o();
}
const et = { duration: 0 };
function Pt(e, t, n) {
  const o = { direction: "in" };
  let i = t(e, n, o), l = !1, c, u, r = 0;
  function s() {
    c && _e(e, c);
  }
  function a() {
    const { delay: f = 0, duration: h = 300, easing: g = Ye, tick: w = N, css: b } = i || et;
    b && (c = Xe(e, 0, 1, h, f, g, b, r++)), w(0, 1);
    const v = Ke() + f, z = v + h;
    u && u.abort(), l = !0, U(() => ue(e, !0, "start")), u = Ge((L) => {
      if (l) {
        if (L >= z)
          return w(1, 0), ue(e, !0, "end"), s(), l = !1;
        if (L >= v) {
          const R = g((L - v) / h);
          w(R, 1 - R);
        }
      }
      return l;
    });
  }
  let d = !1;
  return {
    start() {
      d || (d = !0, _e(e), X(i) ? (i = i(o), $e().then(a)) : a());
    },
    invalidate() {
      d = !1;
    },
    end() {
      l && (s(), l = !1);
    }
  };
}
function Ht(e, t, n) {
  const o = { direction: "out" };
  let i = t(e, n, o), l = !0, c;
  const u = P;
  u.r += 1;
  function r() {
    const { delay: s = 0, duration: a = 300, easing: d = Ye, tick: f = N, css: h } = i || et;
    h && (c = Xe(e, 1, 0, a, s, d, h));
    const g = Ke() + s, w = g + a;
    U(() => ue(e, !1, "start")), Ge((b) => {
      if (l) {
        if (b >= w)
          return f(0, 1), ue(e, !1, "end"), --u.r || I(u.c), !1;
        if (b >= g) {
          const v = d((b - g) / a);
          f(1 - v, v);
        }
      }
      return l;
    });
  }
  return X(i) ? $e().then(() => {
    i = i(o), r();
  }) : r(), {
    end(s) {
      s && i.tick && i.tick(1, 0), l && (c && _e(e, c), l = !1);
    }
  };
}
function tt(e) {
  e && e.c();
}
function ke(e, t, n, o) {
  const { fragment: i, after_update: l } = e.$$;
  i && i.m(t, n), o || U(() => {
    const c = e.$$.on_mount.map(Be).filter(X);
    e.$$.on_destroy ? e.$$.on_destroy.push(...c) : I(c), e.$$.on_mount = [];
  }), l.forEach(U);
}
function Le(e, t) {
  const n = e.$$;
  n.fragment !== null && (At(n.after_update), I(n.on_destroy), n.fragment && n.fragment.d(t), n.on_destroy = n.fragment = null, n.ctx = []);
}
function Mt(e, t) {
  e.$$.dirty[0] === -1 && (G.push(e), Ft(), e.$$.dirty.fill(0)), e.$$.dirty[t / 31 | 0] |= 1 << t % 31;
}
function nt(e, t, n, o, i, l, c, u = [-1]) {
  const r = oe;
  ee(e);
  const s = e.$$ = {
    fragment: null,
    ctx: [],
    props: l,
    update: N,
    not_equal: i,
    bound: Te(),
    on_mount: [],
    on_destroy: [],
    on_disconnect: [],
    before_update: [],
    after_update: [],
    context: new Map(t.context || (r ? r.$$.context : [])),
    callbacks: Te(),
    dirty: u,
    skip_bound: !1,
    root: t.target || r.$$.root
  };
  c && c(s.root);
  let a = !1;
  if (s.ctx = n ? n(e, t.props || {}, (d, f, ...h) => {
    const g = h.length ? h[0] : f;
    return s.ctx && i(s.ctx[d], s.ctx[d] = g) && (!s.skip_bound && s.bound[d] && s.bound[d](g), a && Mt(e, d)), f;
  }) : [], s.update(), a = !0, I(s.before_update), s.fragment = o ? o(s.ctx) : !1, t.target) {
    if (t.hydrate) {
      const d = pt(t.target);
      s.fragment && s.fragment.l(d), d.forEach(F);
    } else
      s.fragment && s.fragment.c();
    t.intro && k(e.$$.fragment), ke(e, t.target, t.anchor, t.customElement), Ze();
  }
  ee(r);
}
class ot {
  $destroy() {
    Le(this, 1), this.$destroy = N;
  }
  $on(t, n) {
    if (!X(n))
      return N;
    const o = this.$$.callbacks[t] || (this.$$.callbacks[t] = []);
    return o.push(n), () => {
      const i = o.indexOf(n);
      i !== -1 && o.splice(i, 1);
    };
  }
  $set(t) {
    this.$$set && !gt(t) && (this.$$.skip_bound = !0, this.$$set(t), this.$$.skip_bound = !1);
  }
}
const ve = window.requestAnimationFrame, zt = window.cancelAnimationFrame, y = function(e, t, ...n) {
  if (typeof e == "function")
    return e.call(t, ...n);
}, ae = function(e) {
  return e === document.body || e === document;
}, jt = /Mobile|Android|iOS|iPhone|iPad|iPod|Windows Phone|KFAPWI/i.test(
  navigator.userAgent
), He = jt ? "touchstart" : "click", qt = /^h(\d)$/i;
let he = 0;
const It = (e, t, n, o, i, l, c) => {
  i = i || "bitoc-heading-", l = l || "bitoc-ml-";
  let u = e.getAttribute("id");
  he = he + 1;
  let r = u;
  u || (u = i + he);
  const s = (e.textContent || "").trim();
  return {
    class: l + t,
    title: s,
    parent: o,
    target: e,
    level: t,
    oriLevel: n,
    id: u,
    oriId: r,
    y: te(e, c).y
  };
}, it = function(e, t) {
  return e ? e.level === t ? e.parent : e.level === t - 1 ? e : it(e.parent, t) : null;
}, Rt = (e, t, n, o, i = 0) => {
  if (!e || !e.length)
    return { nodes: [], offsets: {} };
  const l = {}, c = [];
  let u = null;
  return e.forEach((r) => {
    let s = null;
    const a = qt.exec(r.nodeName);
    a ? s = a[1] - i : s = r.getAttribute("data-level"), s = parseInt(s), s = Math.max(1, Math.min(s, 6)) || 6;
    let d = s, f = null;
    u ? u.level >= s ? (f = it(u.parent, s), d = f ? f.level + 1 : 1) : (d = u.level + 1, f = u) : (d = 1, f = null);
    const h = It(
      r,
      d,
      s,
      f,
      t,
      n,
      o
    );
    f ? f.nodes ? f.nodes.push(h) : f.nodes = [h] : c.push(h), u = h, l[h.y] = h;
  }), { nodes: c, offsets: l };
}, Yt = function(e, t = 16) {
  let n, o = !1, i = Date.now();
  const l = () => {
    o = !0, n && zt(n);
  }, c = () => {
    if (!o) {
      if (Date.now() - i >= t) {
        l(), y(e, this, n);
        return;
      }
      n = ve(c);
    }
  };
  return c(), l;
}, Bt = function(e, t = 24) {
  let n = null;
  return function() {
    const o = this, i = arguments, l = Date.now();
    (!n || l - n > t) && (e.apply(o, i), n = l);
  };
}, Wt = function(e, t, n) {
  (e <= 0 || isNaN(e)) && (e = 500);
  const o = Date.now();
  let i = !0;
  return ve(function l() {
    const c = (Date.now() - o) / e;
    y(t, void 0, c), c >= 1 && (t(1), i = !1, y(n, void 0, 1)), i && ve(l);
  }), function() {
    i = !1;
  };
}, lt = function(e) {
  return e.scrollHeight > e.clientHeight;
}, te = function(e, t) {
  let n = t;
  (!t || ae(t)) && (n = document.documentElement);
  let o = e.offsetTop || 0, i = e.offsetLeft || 0;
  const l = e.offsetParent;
  if (ae(e) || !l)
    return { x: i, y: o };
  if (l === n.offsetParent) {
    const c = n.offsetTop || 0, u = n.offsetLeft || 0;
    return { x: i - u, y: o - c };
  }
  if (l !== n) {
    const c = te(l);
    o += c.y, i += c.x;
  }
  return { x: i, y: o };
}, de = function(e) {
  return e === window ? e.screenY : e === document ? document.scrollingElement.scrollTop : e.scrollTop;
}, Kt = function(e, t, n) {
  if (t && !n)
    return window.getComputedStyle(e).getPropertyValue(t);
  e.style[t] = n;
}, st = function(e) {
  return ae(e) ? document : !e || lt(e) ? e : Kt(e, "position") === "fixed" || !e.parentElement ? document : st(e.parentElement);
}, Me = (e, t, n, o) => {
  let i = 0;
  const l = o || 100;
  return function c(u, r, s) {
    if (de(u) === r)
      i = 0, y(s);
    else {
      if (i > l) {
        i = 0, y(s);
        return;
      }
      i += 1, Yt(() => {
        c(u, r, s);
      });
    }
  }(e, t, n);
}, rt = function(e, t, n = 200, o) {
  if (lt(e)) {
    const i = de(e), l = t - i;
    Wt(
      n,
      (c) => {
        e.scrollTo({
          left: 0,
          top: i + c * l,
          behavior: "smooth"
        });
      },
      o
    );
  } else
    y(o, void 0, 1);
};
function Vt(e) {
  const t = e - 1;
  return t * t * t + 1;
}
const ze = function(e, { delay: t = 0, duration: n = 150, easing: o = Vt } = {}) {
  const i = getComputedStyle(e), l = +i.opacity, c = parseFloat(i.height);
  return {
    delay: t,
    duration: n,
    easing: o,
    css: (u) => `opacity: ${Math.min(u * 20, 1) * l}; max-height: ${u * c}px;`
  };
}, Gt = (e) => {
  let t = 0, n = e.split(",");
  return n.length > 0 && (n[0].trim() == "h2" ? t = 1 : n[0].trim() == "h3" ? t = 2 : n[0].trim() == "h4" ? t = 3 : n[0].trim() == "h5" ? t = 4 : n[0].trim() == "h6" && (t = 5)), t;
}, V = [];
function ft(e, t = N) {
  let n;
  const o = /* @__PURE__ */ new Set();
  function i(u) {
    if (ye(e, u) && (e = u, n)) {
      const r = !V.length;
      for (const s of o)
        s[1](), V.push(s, e);
      if (r) {
        for (let s = 0; s < V.length; s += 2)
          V[s][0](V[s + 1]);
        V.length = 0;
      }
    }
  }
  function l(u) {
    i(u(e));
  }
  function c(u, r = N) {
    const s = [u, r];
    return o.add(s), o.size === 1 && (n = t(i) || N), u(e), () => {
      o.delete(s), o.size === 0 && n && (n(), n = null);
    };
  }
  return { set: i, update: l, subscribe: c };
}
const T = ft(0), ne = ft(null);
function je(e, t, n) {
  const o = e.slice();
  return o[18] = t[n], o;
}
function qe(e) {
  let t, n, o, i, l, c, u = e[0], r = [];
  for (let a = 0; a < u.length; a += 1)
    r[a] = Re(je(e, u, a));
  const s = (a) => M(r[a], 1, 1, () => {
    r[a] = null;
  });
  return {
    c() {
      t = q("div");
      for (let a = 0; a < r.length; a += 1)
        r[a].c();
      A(t, "class", "bitoc-nav");
    },
    m(a, d) {
      H(a, t, d);
      for (let f = 0; f < r.length; f += 1)
        r[f] && r[f].m(t, null);
      i = !0, l || (c = [
        ie(t, "introstart", e[10]),
        ie(t, "introend", e[11]),
        ie(t, "outrostart", e[12]),
        ie(t, "outroend", e[13])
      ], l = !0);
    },
    p(a, d) {
      if (d & 495) {
        u = a[0];
        let f;
        for (f = 0; f < u.length; f += 1) {
          const h = je(a, u, f);
          r[f] ? (r[f].p(h, d), k(r[f], 1)) : (r[f] = Re(h), r[f].c(), k(r[f], 1), r[f].m(t, null));
        }
        for (Oe(), f = u.length; f < r.length; f += 1)
          s(f);
        xe();
      }
    },
    i(a) {
      if (!i) {
        for (let d = 0; d < u.length; d += 1)
          k(r[d]);
        U(() => {
          !i || (o && o.end(1), n = Pt(t, ze, {}), n.start());
        }), i = !0;
      }
    },
    o(a) {
      r = r.filter(Boolean);
      for (let d = 0; d < r.length; d += 1)
        M(r[d]);
      n && n.invalidate(), o = Ht(t, ze, {}), i = !1;
    },
    d(a) {
      a && F(t), wt(r, a), a && o && o.end(), l = !1, I(c);
    }
  };
}
function Ie(e) {
  let t, n;
  return t = new ct({
    props: {
      nodes: e[18].nodes,
      parent: e[18],
      scrollOffset: e[6],
      onNav: e[5],
      scrollElement: e[1],
      scrollDuration: e[2],
      collapsedLevel: e[3],
      transitionEnd: e[7]
    }
  }), {
    c() {
      tt(t.$$.fragment);
    },
    m(o, i) {
      ke(t, o, i), n = !0;
    },
    p(o, i) {
      const l = {};
      i & 1 && (l.nodes = o[18].nodes), i & 1 && (l.parent = o[18]), i & 64 && (l.scrollOffset = o[6]), i & 32 && (l.onNav = o[5]), i & 2 && (l.scrollElement = o[1]), i & 4 && (l.scrollDuration = o[2]), i & 8 && (l.collapsedLevel = o[3]), i & 128 && (l.transitionEnd = o[7]), t.$set(l);
    },
    i(o) {
      n || (k(t.$$.fragment, o), n = !0);
    },
    o(o) {
      M(t.$$.fragment, o), n = !1;
    },
    d(o) {
      Le(t, o);
    }
  };
}
function Re(e) {
  let t, n = e[18].title + "", o, i, l, c, u, r, s, a, d, f = e[18].nodes && e[18].nodes.length && Ie(e);
  return {
    c() {
      t = q("a"), o = Se(n), u = Qe(), f && f.c(), r = Ue(), A(t, "href", i = "#" + e[18].id), A(t, "class", l = e[18].class), Ae(t, "active", e[8] === e[18]);
    },
    m(h, g) {
      H(h, t, g), we(t, o), H(h, u, g), f && f.m(h, g), H(h, r, g), s = !0, a || (d = vt(c = e[9].call(null, t, e[18])), a = !0);
    },
    p(h, g) {
      e = h, (!s || g & 1) && n !== (n = e[18].title + "") && St(o, n), (!s || g & 1 && i !== (i = "#" + e[18].id)) && A(t, "href", i), (!s || g & 1 && l !== (l = e[18].class)) && A(t, "class", l), c && X(c.update) && g & 1 && c.update.call(null, e[18]), (!s || g & 257) && Ae(t, "active", e[8] === e[18]), e[18].nodes && e[18].nodes.length ? f ? (f.p(e, g), g & 1 && k(f, 1)) : (f = Ie(e), f.c(), k(f, 1), f.m(r.parentNode, r)) : f && (Oe(), M(f, 1, 1, () => {
        f = null;
      }), xe());
    },
    i(h) {
      s || (k(f), s = !0);
    },
    o(h) {
      M(f), s = !1;
    },
    d(h) {
      h && F(t), h && F(u), f && f.d(h), h && F(r), a = !1, d();
    }
  };
}
function Jt(e) {
  let t = !e[14](e[8], e[4]), n, o, i = t && qe(e);
  return {
    c() {
      i && i.c(), n = Ue();
    },
    m(l, c) {
      i && i.m(l, c), H(l, n, c), o = !0;
    },
    p(l, [c]) {
      c & 272 && (t = !l[14](l[8], l[4])), t ? i ? (i.p(l, c), c & 272 && k(i, 1)) : (i = qe(l), i.c(), k(i, 1), i.m(n.parentNode, n)) : i && (Oe(), M(i, 1, 1, () => {
        i = null;
      }), xe());
    },
    i(l) {
      o || (k(i), o = !0);
    },
    o(l) {
      M(i), o = !1;
    },
    d(l) {
      i && i.d(l), l && F(n);
    }
  };
}
function Qt(e, t, n) {
  let o, i;
  re(e, T, (_) => n(16, o = _)), re(e, ne, (_) => n(8, i = _));
  let { nodes: l = [] } = t, { scrollElement: c } = t, { scrollDuration: u } = t, { collapsedLevel: r } = t, { parent: s = null } = t, { onNav: a = null } = t, { scrollOffset: d = 0 } = t, { transitionStart: f = null } = t, { transitionEnd: h = null } = t;
  const g = function(_, E) {
    E.element = _;
    let S = E;
    const Y = function(D) {
      D.preventDefault(), C(ne, i = S, i);
      let j = c;
      c.scrollingElement && (j = c.scrollingElement);
      const B = S.y - d;
      C(T, o = o + 1, o), rt(j, B, u, function() {
        if (typeof a != "function") {
          Me(j, B, () => {
            C(T, o = o - 1, o);
          });
          return;
        }
        a(D.target, S, function() {
          Me(j, B, () => {
            C(T, o = o - 1, o);
          });
        });
      });
    };
    return _.addEventListener(He, Y), {
      update(D) {
        S = D, S.element = _;
      },
      destory() {
        E.element = null, S = null, _.removeEventListener(He, Y);
      }
    };
  }, w = (_) => {
    C(T, o = o + 1, o), y(f, void 0, _);
  }, b = (_) => {
    C(T, o = o - 1, o), y(h, void 0, _);
  }, v = (_) => {
    C(T, o = o + 1, o), y(f, void 0, _);
  }, z = (_) => {
    C(T, o = o - 1, o), y(h, void 0, _);
  }, L = function(_, E) {
    return _ && E ? _ === E ? !0 : L(_.parent, E) : !1;
  }, R = function(_, E) {
    return !_ || !E ? !1 : E.level + 1 > r && !L(_, E);
  };
  return e.$$set = (_) => {
    "nodes" in _ && n(0, l = _.nodes), "scrollElement" in _ && n(1, c = _.scrollElement), "scrollDuration" in _ && n(2, u = _.scrollDuration), "collapsedLevel" in _ && n(3, r = _.collapsedLevel), "parent" in _ && n(4, s = _.parent), "onNav" in _ && n(5, a = _.onNav), "scrollOffset" in _ && n(6, d = _.scrollOffset), "transitionStart" in _ && n(15, f = _.transitionStart), "transitionEnd" in _ && n(7, h = _.transitionEnd);
  }, [
    l,
    c,
    u,
    r,
    s,
    a,
    d,
    h,
    i,
    g,
    w,
    b,
    v,
    z,
    R,
    f
  ];
}
class ct extends ot {
  constructor(t) {
    super(), nt(this, t, Qt, Jt, ye, {
      nodes: 0,
      scrollElement: 1,
      scrollDuration: 2,
      collapsedLevel: 3,
      parent: 4,
      onNav: 5,
      scrollOffset: 6,
      transitionStart: 15,
      transitionEnd: 7
    });
  }
}
function Ut(e) {
  yt(e, "svelte-f3ug8b", '.bitoc.svelte-f3ug8b.svelte-f3ug8b,.bitoc.svelte-f3ug8b .svelte-f3ug8b{box-sizing:border-box}.bitoc-fixed{position:fixed !important}.bitoc.svelte-f3ug8b.svelte-f3ug8b{width:100%;position:relative;overflow-y:auto;-ms-overflow-style:none;overflow:-moz-scrollbars-none;scroll-behavior:smooth}.bitoc.svelte-f3ug8b.svelte-f3ug8b::-webkit-scrollbar{width:0 !important}.bitoc-nav a{display:block;padding:0.2rem 1.7rem;font-size:0.9rem;text-decoration:none;color:#555;position:relative;transition:all 0.25s}.bitoc-nav{overflow:hidden;transition:max-height 0.25s}.bitoc-nav a:before{content:" ";height:0.25rem;width:0.25rem;background:#555;position:absolute;top:0.72rem;left:1rem}.bitoc-nav a:hover, .bitoc-nav a.active{color:#009a61}.bitoc-nav a.active::before, .bitoc-nav a:hover:before{background:#009a61}.bitoc-nav a.bitoc-ml-2{margin-left:1rem !important}.bitoc-nav a.bitoc-ml-3{margin-left:2rem !important}.bitoc-nav a.bitoc-ml-4{margin-left:3rem !important}.bitoc-nav a.bitoc-ml-5{margin-left:4rem !important}.bitoc-nav a.bitoc-ml-6{margin-left:5rem !important}');
}
function Xt(e) {
  let t;
  return {
    c() {
      t = q("div"), t.textContent = "\u672C\u7BC7\u76EE\u5F55", A(t, "class", "toc-title");
    },
    m(n, o) {
      H(n, t, o);
    },
    d(n) {
      n && F(t);
    }
  };
}
function Zt(e) {
  let t = !e[3](), n, o, i, l, c, u = t && Xt();
  return l = new ct({
    props: {
      scrollOffset: e[2],
      collapsedLevel: e[0],
      scrollDuration: e[1],
      nodes: e[4],
      scrollElement: e[6],
      transitionEnd: e[7]
    }
  }), {
    c() {
      u && u.c(), n = Qe(), o = q("main"), i = q("div"), tt(l.$$.fragment), A(i, "class", "bitoc-navs svelte-f3ug8b"), A(o, "class", "bitoc svelte-f3ug8b");
    },
    m(r, s) {
      u && u.m(r, s), H(r, n, s), H(r, o, s), we(o, i), ke(l, i, null), e[20](o), c = !0;
    },
    p(r, s) {
      const a = {};
      s[0] & 4 && (a.scrollOffset = r[2]), s[0] & 1 && (a.collapsedLevel = r[0]), s[0] & 2 && (a.scrollDuration = r[1]), s[0] & 16 && (a.nodes = r[4]), l.$set(a);
    },
    i(r) {
      c || (k(l.$$.fragment, r), c = !0);
    },
    o(r) {
      M(l.$$.fragment, r), c = !1;
    },
    d(r) {
      u && u.d(r), r && F(n), r && F(o), Le(l), e[20](null);
    }
  };
}
function $t(e, t, n) {
  let o, i;
  re(e, T, (m) => n(24, o = m)), re(e, ne, (m) => n(25, i = m));
  let { contentElement: l } = t, { scrollElement: c } = t, { fixedElement: u } = t, { headingSelector: r } = t, { collapsedLevel: s = 3 } = t, { idPrefix: a = "" } = t, { levelClassPrefix: d = "" } = t, { scrollDuration: f = 200 } = t, { fixedOffset: h = 0 } = t, { fixedClassName: g = "bitoc-fixed" } = t, { scrollOffset: w = 0 } = t, { beforeFixed: b = null } = t, { afterFixed: v = null } = t;
  const z = function() {
    B(), Z();
  }, L = function() {
    return _.length === 0;
  }, R = function() {
    Y = te(u || S, document.documentElement).y, Z();
  };
  let _ = [], E = {}, S = null, Y = 0, D = st(c), j = [];
  const B = function() {
    const m = r || "h1, h2, h3, h4, h5, h6", O = l.querySelectorAll(m), p = Gt(m), x = Rt(O, a, d, D, p);
    n(4, _ = x.nodes), E = x.offsets, j = Object.keys(E).map(Number);
    const W = De();
    E[W] && C(ne, i = E[W], i);
  }, De = function() {
    const m = de(D);
    return j.find((O) => O >= m);
  }, ut = function(m) {
    if (L())
      return;
    const O = De(), p = E[O];
    if (O !== void 0 && p) {
      C(ne, i = p, i);
      const x = p.element;
      at(x, m);
    } else
      y(m);
  }, at = function(m, O) {
    if (L()) {
      y(O);
      return;
    }
    let p = S;
    if (m && p) {
      let x = te(m, p).y;
      const W = p.offsetHeight, Ce = p.scrollHeight - W, Fe = W / 2;
      x <= Fe ? x = 0 : x - W > Ce ? x = Ce : x = x - Fe, rt(p, x, f, () => {
        y(O);
      });
    } else
      y(O);
  }, dt = function() {
    if (!L() && h !== !1 && g && ae(D)) {
      const m = u || S, O = de(document);
      let p = h;
      if (p || (p = Y), O >= p) {
        if (!m.classList.contains(g)) {
          if (y(b, void 0, !0) === !1)
            return;
          m.classList.add(g), y(v, void 0, !0);
        }
      } else if (m.classList.contains(g)) {
        if (y(b, void 0, !1) === !1)
          return;
        m.classList.remove(g), y(v, void 0, !1);
      }
    }
  }, Ne = function() {
    dt(), o === 0 && ut();
  }, Z = function() {
    ht();
  }, mt = () => {
    Ne();
  }, ht = Bt(Ne, 16);
  Nt(() => (Y = te(u || S, document.documentElement).y, Z(), D.addEventListener("scroll", Z), () => {
    D.removeEventListener("scroll", Z);
  }));
  function _t(m) {
    ge[m ? "unshift" : "push"](() => {
      S = m, n(5, S);
    });
  }
  return e.$$set = (m) => {
    "contentElement" in m && n(8, l = m.contentElement), "scrollElement" in m && n(9, c = m.scrollElement), "fixedElement" in m && n(10, u = m.fixedElement), "headingSelector" in m && n(11, r = m.headingSelector), "collapsedLevel" in m && n(0, s = m.collapsedLevel), "idPrefix" in m && n(12, a = m.idPrefix), "levelClassPrefix" in m && n(13, d = m.levelClassPrefix), "scrollDuration" in m && n(1, f = m.scrollDuration), "fixedOffset" in m && n(14, h = m.fixedOffset), "fixedClassName" in m && n(15, g = m.fixedClassName), "scrollOffset" in m && n(2, w = m.scrollOffset), "beforeFixed" in m && n(16, b = m.beforeFixed), "afterFixed" in m && n(17, v = m.afterFixed);
  }, B(), [
    s,
    f,
    w,
    L,
    _,
    S,
    D,
    mt,
    l,
    c,
    u,
    r,
    a,
    d,
    h,
    g,
    b,
    v,
    z,
    R,
    _t
  ];
}
class en extends ot {
  constructor(t) {
    super(), nt(
      this,
      t,
      $t,
      Zt,
      ye,
      {
        contentElement: 8,
        scrollElement: 9,
        fixedElement: 10,
        headingSelector: 11,
        collapsedLevel: 0,
        idPrefix: 12,
        levelClassPrefix: 13,
        scrollDuration: 1,
        fixedOffset: 14,
        fixedClassName: 15,
        scrollOffset: 2,
        beforeFixed: 16,
        afterFixed: 17,
        reset: 18,
        isEmpty: 3,
        syncScroll: 19
      },
      Ut,
      [-1, -1]
    );
  }
  get reset() {
    return this.$$.ctx[18];
  }
  get isEmpty() {
    return this.$$.ctx[3];
  }
  get syncScroll() {
    return this.$$.ctx[19];
  }
}
const le = function(e, t, n, o) {
  if (!(!e && o)) {
    if (typeof e == "string" && (e = document.querySelector(e)), !(e instanceof HTMLElement))
      if (n)
        e = n;
      else
        throw new Error(`"${t}"is an invalid selector or non-DOM node`);
    return e;
  }
};
class nn {
  constructor(t, n) {
    const {
      contentSelector: o,
      scrollSelector: i,
      fixedSelector: l,
      headingSelector: c,
      collapsedLevel: u,
      idPrefix: r,
      levelClassPrefix: s,
      scrollDuration: a,
      fixedOffset: d,
      fixedClassName: f,
      scrollOffset: h,
      beforeFixed: g,
      afterFixed: w
    } = n || {};
    t = le(t, "mount");
    const b = le(
      o,
      "contentSelector",
      document.body
    ), v = le(
      i,
      "scrollSelector",
      document.body
    ), z = le(l, "fixedSelector", null, !0);
    this.toc = new en({
      target: t,
      props: {
        contentElement: b,
        scrollElement: v,
        fixedElement: z,
        headingSelector: c,
        collapsedLevel: Math.max(1, Math.min(u, 6)) || 3,
        idPrefix: r,
        levelClassPrefix: s,
        scrollDuration: a,
        fixedOffset: d,
        fixedClassName: f,
        scrollOffset: h,
        beforeFixed: g,
        afterFixed: w
      }
    });
  }
  reset() {
    this.toc.reset();
  }
  isEmpty() {
    return this.toc.isEmpty();
  }
  syncScroll() {
    this.toc.syncScroll();
  }
}
export {
  nn as default
};
